﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilmManagement2.Founction;
using System.Data;
using System.Data.SqlClient;

namespace FilmManagement2.WebPage
{
    public partial class BookPage_1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        protected void admin_Click(object sender, EventArgs e)
        {

            if (submit.Visible == false)
            {
                submit.Visible = true;
                accountlbl.Visible = true;
                txtAccount.Visible = true;
                passwordlbl.Visible = true;
                txtPassword.Visible = true;
            }
            else
            {
                submit.Visible = false;
                accountlbl.Visible = false;
                txtAccount.Visible = false;
                passwordlbl.Visible = false;
                txtPassword.Visible = false;
            }

        }

        protected void submit_Click(object sender, EventArgs e)
        {
            ConnectToSql cts = new ConnectToSql();
            if (cts.AdminLog(txtAccount.Text, txtPassword.Text))
            {
                Session["AdminName"] = txtAccount.Text;
                Response.Redirect(@"AdminPage.aspx");
            }
            else
            {
                Response.Write("<script>alert('登陆失败')</script>");

            }

        }

        protected void bookticketbut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"BookPage_1.aspx");
        }

        protected void suggestbut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"SuggestionPage.aspx");
        }

        protected void hombut_Click(object sender, EventArgs e)
        {
            Response.Redirect(@"MainPage.aspx");
        }

        protected void FilmNameList_SelectedIndexChanged(object sender, EventArgs e)
        {
            FilmDateList.Items.Clear();
            ConnectToSql cts = new ConnectToSql();
            int id = Convert.ToInt32(FilmNameList.SelectedValue.ToString());
            DataSet ds = cts.GetFilmByID(id);
            string path=ds.Tables[0].Rows[0][4].ToString();
            path = path.Substring(40);
            path = "~"+path.Replace(@"\",@"/");
            Image1.ImageUrl = path;
            pricelbl2.Text=ds.Tables[0].Rows[0][5].ToString();
           DataSet dsStudioOne=cts.GetStudioOneDetailByID(id);
           for (int i = 0; i < dsStudioOne.Tables[0].Rows.Count; i++)
           {
              FilmDateList.Items.Add(dsStudioOne.Tables[0].Rows[i][2].ToString());
           }
           DataSet dsStudioTwo = cts.GetStudioTwoDetailByID(id);
           for (int i = 0; i < dsStudioTwo.Tables[0].Rows.Count; i++)
           {
               FilmDateList.Items.Add(dsStudioTwo.Tables[0].Rows[i][2].ToString());
           }
           DataSet dsStudioThree = cts.GetStudioThreeDetailByID(id);
           for (int i = 0; i < dsStudioThree.Tables[0].Rows.Count; i++)
           {
               FilmDateList.Items.Add(dsStudioThree.Tables[0].Rows[i][2].ToString());
           }



        }

        protected void GoToBookPage_2_Click(object sender, EventArgs e)
        {

            if (FilmNameList.SelectedIndex == -1)
            {
                Response.Write("<script>alert('请选择您要观看的电影')</script>");
            }
            else
            {
                if(FilmDateList.SelectedIndex==-1)
                {
                    Response.Write("<script>alert('请选择您要观看的电影的时间')</script>");
                }
                else
                {
                Session["SelectTime"] = FilmDateList.SelectedItem.ToString();
                Session["FilmId"] = FilmNameList.SelectedValue;
                Response.Redirect(@"BookPage_2.aspx");
                }
            }
        }
    }
}